<template>
	<view style="padding-bottom: 130rpx;">
		<view class="column centre-user" :style="`padding-top:${heightTop}rpx`">
			<view class="row user-row" style="align-items: center;"
				@click="navTo('/pages/user/user-update/user-update')">
				<image :src="userInfo.wxHeadimgurl||'/static/user-my.jpg'" mode=""></image>
				<view class="column centre">
					<view class="row " style="align-items: center;">
						<view class="" style="width: 230rpx;">
							<text style="font-weight: 800;overflow: hidden;text-overflow: clip;display: -webkit-box;white-space: nowrap">{{userInfo.wxNickname||"暂无"}}</text>
						</view>
						<view class="row align-items-center" :class="userInfo.wxSex==1?'gender-male':'gender-female'"
							style="width: 40rpx;height: 40rpx;border-radius: 50%;margin-left: 20rpx;">
							<zywork-icon :type="userInfo.wxSex ==1?'icon-nan':'icon-nv'" color="#ffffff" size="30">
							</zywork-icon>
						</view>
					</view>
					<view class="row text-base" style="margin-top: 50rpx;">
						{{userInfo.phone || '暂无绑定手机号'}}
					</view>
				</view>
				<view class="" style="margin-left: auto;width: 30rpx;height: 30rpx;">
					<zywork-icon type="icon-youjiantou1" size="30" color="#dcdcdc "></zywork-icon>
				</view>
			</view>
			<view class="row integral" style="">
				<view class="column align-items-center" @click="navTo('/pages/user/my-integral/my-integral')">
					<text class="text-lg">{{userInfo.totalPoints||0.00}}</text>
					<text style="color: #9B9B9B;">云豆</text>-
				</view>
				<!-- <view class="" style="width: 2rpx;height: 100rpx;background-color: #f2f2f2;">

				</view> -->
				<!-- <view class="column align-items-center">
					<text class="text-lg">0.00</text>
					<text style="color: #9B9B9B;">青豆</text>
				</view> -->
			</view>
		</view>
		<view class="blank" :style="`margin-top:${marginTop}px`">

		</view>
		<custom-list-item iconImg="/static/withdraw/withdraw.png" @click="navTo('/pages/user/my-integral/my-integral')" title="云豆提现"></custom-list-item>
		<custom-list-item iconImg="/static/icon_my_code@3x.png" @click="navTo('/pages/user/my-QR-code/my-QR-code')" title="我的二维码"></custom-list-item>
		<custom-list-item iconImg="/static/icon_my_grade@3x.png" @click="navTo(`/pages/user/my-grades/my-grades?rcode=${userInfo.rcode}`)" title="我的等级"></custom-list-item>
		<!-- <view class="blank" ></view> -->
		<custom-list-item iconImg="/static/icon_my_order@3x.png" @click="navTo('/pages/user/order/order_list')" title="我的订单"></custom-list-item>
		<!-- <custom-list-item iconImg="/static/icon_my_receive@3x.png" @click="navTo('/pages/user/take-records/take-records')" title="领取记录"></custom-list-item> -->
		<!-- <custom-list-item iconImg="/static/icon_my_Inspection@3x.png" title="巡检记录"></custom-list-item> -->
		<!-- <view class="blank" ></view> -->
		<custom-list-item iconImg="/static/icon_my_feedback@3x.png" @click="navTo('/pages/user/feedback/feedback')" title="反馈"></custom-list-item>
		<custom-list-item iconImg="/static/setting.png" @click="navTo('/pages/user/my-setting/my-setting')" title="设置"></custom-list-item>
		<custom-tab-bar :isAndroid="isAndroid" :current="3" @click="switchTabs"></custom-tab-bar>
	</view>
</template>

<script>
	import {mapMutations} from 'vuex';
	export default {
		data() {
			return {
				heightTop: 80,
				marginTop: 0,
				userInfo: {},
				backButtonPress: 0 ,//监听退出应用的事件
				isAndroid:true //判断是否是安卓环境
			};
		},
		created() {
			uni.hideTabBar({})
			this.heightTop += uni.getSystemInfoSync().statusBarHeight
			setTimeout(() => {
				this.$nextTick(() => {
					var query = uni.createSelectorQuery().in(this);
					query.select('.centre-user').boundingClientRect();
					query.exec(data => {
						this.marginTop = data[0].height
					});
				})
			}, 100)
		},
		onShow() {
			this.getUserInfo();
			this.isAndroid = getApp().globalData.isAndroid;
		},
		onBackPress() {
			this.backButtonPress++;
			if (this.backButtonPress > 1) {
				this.logout();
				plus.runtime.quit();
			} else {
				plus.nativeUI.toast('再按一次退出应用');
			}
			setTimeout(function() {
				this.backButtonPress = 0;
			}, 1000);
			return true;
		},
		methods: {
			...mapMutations(['logout']),
			getUserInfo() {
				console.log("获取个人信息")
				this.$util.doGet('/user/manager/userInfoList', {}, {}, true).then(res => {
					console.log(res.data)
					if (res.data.code == this.$ResponseStatus.OK) {
						uni.setStorageSync(this.$util.USER_INFO, res.data.data)
						this.userInfo = res.data.data || {}
						if (this.userInfo.phonenumber) {
							this.userInfo.phone = this.$util.noPassByMobile(this.userInfo.phonenumber + "")
						}
					}
				}).catch(error => {
					console.log(error)
				})
			},
			switchTabs(data) {
				if(data.index === 2&& !this.isAndroid){
					this.scan();
					return
				}
				uni.switchTab({
					url: data.url
				})
			},
			scan(){
				uni.scanCode({
					success: res => {
						uni.showLoading({
							title: "开始识别"
						})
						this.scanResult(res.result);
					}
				})
			},
			scanResult(result) {
				uni.showLoading({
					title: "开始识别"
				})
				this.$util.doGet(
					`/api/yun-bag/equipment/spread-qr-equipment/analysis/info?qrContent=${result}`, {}, {},
					true).then(res => {
					uni.hideLoading()
					console.log("设备信息", res.data)
					this.equipment = res.data
					if (this.equipment.id) {
						this.navTo(
							`/pages/index/equipment-info/equipment-info?equipment=${JSON.stringify(this.equipment)}`
							)
					} else {
						this.$util.showInfoToast("没有识别到设备信息")
					}
				}).catch(error => {
					console.log(error)
					uni.hideLoading()
				})
			},
			navTo(url) {
				if(!this.userInfo.phonenumber&&url.indexOf('my-integral') != -1&&this.isAndroid){
					url = "/pages/user/my-setting/update-Phone/update-Phone"
				}
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	.centre-user {
		width: 750rpx;
		position: fixed;
		z-index: 900;
		top: 0rpx;
		background-color: #FFFFFF;

		.user-row {
			padding: 20rpx 30rpx;

			image {
				width: 220rpx;
				height: 220rpx;
				border-radius: 50%;
			}

			.centre {
				margin-left: 20rpx;
				width: 300rpx;
				height: 180rpx;
			}

		}
	}



	.text-lg {
		font-size: 60rpx;
		color: #0897f7;
		font-weight: 800;
	}

	.text-base {
		font-size: $uni-font-size-base;
	}

	.integral {
		height: 130rpx;
		padding: 20rpx 40rpx;
		justify-content: space-around;
		align-items: center;
	}

	.list-item {
		padding: 20rpx 30rpx;
		align-items: center;

		image {
			width: 70rpx;
			height: 70rpx;
		}

		text {
			margin-left: 30rpx;
			font-size: 38rpx;
		}
	}
</style>
